package com.example.mydesignmodule.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tgw
 * @date 2021/3/3
 * @describe
 */
class ArrayCreateIterator<T> implements Iterator<T> {

    private T[] list;
    private int index = 0;

    public ArrayCreateIterator(T[] list) {
        this.list = list;
    }

    @Override
    public boolean hashNext() {
        return (list.length - 1 >= index && list[index] != null);
    }

    @Override
    public T next() {
        T t = null;
        if (hashNext()) {
            t = list[ index ++];
        }
        return  t;
    }
}
